package clients;

import shared.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Scanner;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class LogOnWindow extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textFieldRemoteHost;
	private JTextField textFieldUsername;


	/**
	 * Create the dialog.
	 */
	public LogOnWindow() {
		
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
				
		setBounds(100, 100, 500, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblRemoteHost = new JLabel("Remote Host:");
			lblRemoteHost.setBounds(25, 78, 77, 14);
			contentPanel.add(lblRemoteHost);
		}
		{
			textFieldRemoteHost = new JTextField();
			textFieldRemoteHost.setBounds(127, 75, 136, 20);
			contentPanel.add(textFieldRemoteHost);
			textFieldRemoteHost.setColumns(10);
		}
		{
			JLabel lblUsername = new JLabel("Username:");
			lblUsername.setBounds(25, 133, 77, 14);
			contentPanel.add(lblUsername);
		}
		{
			textFieldUsername = new JTextField();
			textFieldUsername.setBounds(127, 130, 136, 20);
			contentPanel.add(textFieldUsername);
			textFieldUsername.setColumns(10);
		}
		{
			JLabel lblleaveBlankFro = new JLabel("( leave blank for localhost )");
			lblleaveBlankFro.setBounds(273, 78, 175, 14);
			contentPanel.add(lblleaveBlankFro);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("Log On");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) 
					{
						Client.remoteHostName = textFieldRemoteHost.getText();
						Client.userName       = textFieldUsername.getText();
						dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Exit");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) 
					{
						Client.exit = true;
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

}
